<?php

$head_photo_url = empty($model->picture) ? Yii::app()->baseUrl . '/img/user-128.png' : $model->picture;
?>
<div class="row-fluid">
	<div class="span3">
		<div class="row-fluid">
			<div class="span12 text-center">
				<p>
					<img class="img-polaroid" src="<?php echo $head_photo_url; ?>" style="width:50px;" />
				</p>
				<h4 style="font-weight:normal;" class="hidden">
					ID: <strong><?php echo Yii::app()->user->id; ?></strong>
				</h4>
			</div>
		</div>
	</div>
	<div class="span9">
<?php $form = $this->beginWidget('CActiveForm', array(
	'id'=>'user-form',
	'enableAjaxValidation'=>true,
	'enableClientValidation'=>true,
	'clientOptions'=>array(
		'validateOnSubmit'=>true,
	),
)); ?>
	<label class="control-label"><?php echo $form->labelEx($model,'name'); ?></label>
	<div class="controls controls-row">
		<?php echo $form->textField($model, 'name', array('class'=>'span6')); ?>
	</div>
	<div class="space"></div>

	<label class="control-label"><?php echo $form->labelEx($model,'mobile'); ?></label>
	<div class="controls controls-row">
		<?php echo $form->textField($model, 'mobile', array('class'=>'span6')); ?>
	</div>
	<div class="space"></div>

	<label class="control-label"><?php echo $form->labelEx($model,'email'); ?></label>
	<div class="controls controls-row">
		<?php echo $form->textField($model, 'email', array('class'=>'span6')); ?>
	</div>
	<div class="space"></div>

	<label class="control-label"><?php echo $form->labelEx($model,'lang'); ?></label>
	<div class="controls controls-row">
		<?php echo CHtml::dropDownList('lang', substr(Yii::app()->user->lang, 0, 2), array(
			'en' => 'English',
			'fi' => 'Finnish',
		), array()); ?>
	</div>
	<hr />
	<div class="errorMessage"></div>
	<button class="btn btn-large btn-primary" id="update-settings"><?php echo BUtils::T('update_lbl'); ?></button>
<?php $this->endWidget(); ?>
	</div>
</div>
<script>
$(function() {
	$('#update-settings').click(function(ev){
		ev.preventDefault();
		var _this = $(this);
		var _form = $(this).parent('form');
		$.ajax({
			url: _form.attr('action'), data: _form.serialize(), type: 'POST',
			beforeSend: function() {
				_this.attr('disabled', true);
				$('.errorMessage').html('');
			},
			error: function(jqXHR) {
				_this.attr('disabled', false);
				$('.errorMessage').html(jqXHR.responseText);
			},
			success: function(html) {
				_this.attr('disabled', false);
				alert(html);
			}
		});
	});
});
</script>